class OrgsTeams
  attr_accessor :github

  def initialize(github)
    @github = github
  end

  def listTeams(org)
    @github.get('orgs/%s/teams' % org)
  end

  def getTeam(id)
    @github.get('teams/%s' % id)
  end

  def createTeam(org, name, repo_names=nil, permission=nil)
    params = {
        :name => name,
        :repo_names => repo_names,
        :permission => permission
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    @github.post('orgs/%s/teams' % org, data)
  end

  def editTeam(id, name, permission=nil)
    params = {
        :name => name,
        :permission => permission
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    @github.patch('teams/%s' % id, data)
  end

  def deleteTeam(id)
    @github.delete('teams/%s' % id)
  end

  def listTeamMembers(id)
    @github.get('teams/%s/members' % id)
  end

  def getTeamMember(id, user=nil)
    username = user == nil ? @github.username : user
    @github.get('teams/%s/members/%s' % [id, username])
  end

  def addTeamMember(id, user)
    username = user == nil ? @github.username : user
    @github.put('teams/%s/members/%s' % [id, username])
  end

  def deleteTeamMember(id, user)
    username = user == nil ? @github.username : user
    @github.delete('teams/%s/members/%s' % [id, username])
  end

  def listTeamRepos(id)
    @github.get('teams/%s/repos' % id)
  end

  def getTeamRepo(id, user, repo)
    username = user == nil ? @github.username : user
    @github.get('teams/%s/repos/%s/%s' % [id, username, repo])
  end

  def addTeamRepo(id, user, repo)
    username = user == nil ? @github.username : user
    @github.put('teams/%s/repos/%s/%s' % [id, username, repo])
  end

  def removeTeamRepo(id, user, repo)
    username = user == nil ? @github.username : user
    @github.delete('teams/%s/repos/%s/%s' % [id, username, repo])
  end
end